using System;
using System.Threading.Tasks;

namespace Runtime.DesignPattern
{
    public interface IEventManager
    {
        // 事件订阅
        void Subscribe(string eventType, IEventHandler handler);
        void Subscribe<TData>(IEventHandler<TData> handler) where TData : struct;
        void Unsubscribe(string eventType, IEventHandler handler);
        void Unsubscribe<TData>(IEventHandler<TData> handler) where TData : struct;

        // 事件发布
        Task PublishAsync(IEvent @event);
        Task PublishAsync(string eventType, object eventData, string sourceId, string targetId = null);
        Task PublishAsync<TData>(IEvent<TData> @event) where TData : struct;
        Task PublishAsync<TData>(string eventType, TData eventData, string sourceId, string targetId = null) where TData : struct;

        // 事件管理
        void ClearAllSubscriptions();
        bool HasSubscribers(string eventType);
        bool HasSubscribers<TData>() where TData : struct;

        // 事件过滤
        void AddEventFilter(string eventType, Func<IEvent, bool> filter);
        void AddEventFilter<TData>(Func<IEvent<TData>, bool> filter) where TData : struct;
        void RemoveEventFilter(string eventType, Func<IEvent, bool> filter);
        void RemoveEventFilter<TData>(Func<IEvent<TData>, bool> filter) where TData : struct;

        // 事件优先级
        void SetHandlerPriority(IEventHandler handler, int priority);
        int GetHandlerPriority(IEventHandler handler);
    }
}